package com.lp.biz.member.controller;

import com.lp.biz.member.model.query.*;
import com.lp.biz.member.model.vo.AddBlackList;
import com.lp.biz.member.model.vo.CreateTrainManage;
import com.lp.biz.member.service.MemberService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.CommonConstant.NEGATE;
import static com.lp.common.constant.CommonConstant.SURE;
import static com.lp.common.constant.IdentityConstant.*;
import static com.lp.common.constant.MenuConstant.*;

/**
 * MemberController
 * @program: backend
 * @author Ke.Song
 * @since 2024-05-03 11:30:02
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    /**
     * 获取用户下拉
     * @param nickName 昵称
     * @param phone 手机号
     * @return 查询结果
     */
    @GetMapping("/drop-down")
    @PermissionAnnotation()
    public CommonResult getMemberList(String nickName, String phone) {
        return memberService.getMemberList(nickName, phone);
    }

    /**
     * 获取普通用户列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/normal")
    @PermissionAnnotation(menus = {USER_NORMAL_MEMBER})
    public CommonResult getNormalMemberList(NormalMemberQuery query) {
        return memberService.getNormalMemberList(query);
    }

    /**
     * 获取共读会会员列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/reading")
    @PermissionAnnotation(menus = {USER_READING_MEMBERS})
    public CommonResult getReadingMemberList(NormalMemberQuery query) {
        return memberService.getReadingMemberList(query);
    }

    /**
     * 获取训练营会员列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/train")
    @PermissionAnnotation(menus = {USER_TRAINING_STUDENT})
    public CommonResult getTrainStudent(TrainStudentQuery query) {
        return memberService.getTrainStudent(query);
    }

    /**
     * 获取教练列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/trainer")
    @PermissionAnnotation(menus = {USER_TRAINER})
    public CommonResult getTrainerList(TrainMemberQuery query) {
        return memberService.getTrainManageList(query, CATEGORY_TRAINER);
    }

    /**
     * 增加教练
     * @param manage 增加参数
     * @return 处理结果
     */
    @PostMapping("/trainer")
    @PermissionAnnotation(menus = {USER_TRAINER})
    public CommonResult addTrainer(@RequestBody @Validated CreateTrainManage manage) {
        manage.setCategory(CATEGORY_TRAINER);
        memberService.addTrainManage(manage);
        return CommonResult.success();
    }

    /**
     * 获取班主任列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/class-teacher")
    @PermissionAnnotation(menus = {USER_CLASS_TEACHER})
    public CommonResult getClassTeacherList(TrainMemberQuery query) {
        return memberService.getTrainManageList(query, CLASS_TEACHER);
    }

    /**
     * 增加班主任
     * @param manage 增加参数
     * @return 处理结果
     */
    @PostMapping("/class-teacher")
    @PermissionAnnotation(menus = {USER_TRAINER})
    public CommonResult addClassTeacher(@RequestBody @Validated CreateTrainManage manage) {
        manage.setCategory(CLASS_TEACHER);
        memberService.addTrainManage(manage);
        return CommonResult.success();
    }

    /**
     * 获取导师列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/mentor")
    @PermissionAnnotation(menus = {USER_MENTOR})
    public CommonResult getMentorList(TrainMemberQuery query) {
        return memberService.getTrainManageList(query, CATEGORY_MENTOR);
    }

    /**
     * 增加导师
     * @param manage 增加参数
     * @return 处理结果
     */
    @PostMapping("/mentor")
    @PermissionAnnotation(menus = {USER_MENTOR})
    public CommonResult addMentor(@RequestBody @Validated CreateTrainManage manage) {
        manage.setCategory(CATEGORY_MENTOR);
        memberService.addTrainManage(manage);
        return CommonResult.success();
    }

    /**
     * 获取助教列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/assistant")
    @PermissionAnnotation(menus = {USER_ASSISTANT})
    public CommonResult getAssistantList(TrainMemberQuery query) {
        return memberService.getTrainManageList(query, CATEGORY_ASSISTANT);
    }

    /**
     * 增加助教
     * @param manage 增加参数
     * @return 处理结果
     */
    @PostMapping("/assistant")
    @PermissionAnnotation(menus = {USER_ASSISTANT})
    public CommonResult addAssistant(@RequestBody @Validated CreateTrainManage manage) {
        manage.setCategory(CATEGORY_ASSISTANT);
        memberService.addTrainManage(manage);
        return CommonResult.success();
    }

    /**
     * 获取知识顾问列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/advisors")
    @PermissionAnnotation(menus = {USER_ADVISOR})
    public CommonResult getAdvisors(AdvisorQuery query) {
        return memberService.getAdvisors(query);
    }

    /**
     * 获取用户详情
     * @param memberId 用户id
     * @return 查询结果
     */
    @GetMapping("/{memberId}")
    @PermissionAnnotation
    public CommonResult getMemberDetail(@PathVariable Integer memberId) {
        return memberService.getMemberDetail(memberId);
    }

    /**
     * 获取用户详情订单记录
     * @param memberId 用户id
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/{memberId}/orders")
    @PermissionAnnotation
    public CommonResult getMemberOrders(PageParams query, @PathVariable Integer memberId) {
        return memberService.getMemberOrders(query, memberId);
    }

    /**
     * 获取用户详情邀请记录
     * @param memberId 用户id
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/{memberId}/invitation")
    @PermissionAnnotation
    public CommonResult getMemberInvitationList(PageParams query, @PathVariable Integer memberId) {
        return memberService.getMemberInvitationList(query, memberId);
    }

    /**
     * 增加黑名单
     * @param memberId 用户id
     * @return 处理结果
     */
    @PutMapping("/{memberId}/blacklist")
    @PermissionAnnotation
    public CommonResult addBlackList(@PathVariable Integer memberId, @RequestBody@Validated AddBlackList params) {
        memberService.addOrUpdateBlackList(memberId, params.getReason());
        return CommonResult.success();
    }

    /**
     * 获取用户详情学习记录
     * @param memberId 用户id
     * @param query 查询记录
     * @return 查询记录
     */
    @GetMapping("/{memberId}/study")
    @PermissionAnnotation
    public CommonResult getStudyList(PageParams query, @PathVariable Integer memberId) {
        return memberService.getStudyList(query, memberId);
    }

    /**
     * 获取用户详情活动记录
     * @param memberId 用户id
     * @param query 查询记录
     * @return 查询记录
     */
    @GetMapping("/{memberId}/activity")
    @PermissionAnnotation
    public CommonResult getActivityList(PageParams query, @PathVariable Integer memberId) {
        return memberService.getActivityList(query, memberId);
    }

    /**
     * 获取用户详情文章记录
     * @param memberId 用户id
     * @param query 查询记录
     * @return 查询记录
     */
    @GetMapping("/{memberId}/article")
    @PermissionAnnotation
    public CommonResult getArticleList(PageParams query, @PathVariable Integer memberId) {
        return memberService.getArticleList(query, memberId);
    }

    /**
     * 获取退休人员申请列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/pension")
    @PermissionAnnotation(menus = {USER_PENSION})
    public CommonResult getPension(PensionQuery query) {
        return memberService.getPension(query);
    }

    /**
     * 获取退休人员列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/pension/members")
    @PermissionAnnotation(menus = {USER_PENSION})
    public CommonResult getPensionMembers(PensionQuery query) {
        return memberService.getPensionMembers(query);
    }

    /**
     * 申请列表明细
     * @param pensionId 申请记录id
     * @return 查询结果
     */
    @GetMapping("/pension/{pensionId}")
    @PermissionAnnotation(menus = {USER_PENSION})
    public CommonResult getPensionDetail(@PathVariable Integer pensionId, PensionQuery query) {
        return memberService.getPensionDetail(pensionId, query);
    }

    /**
     * 通过退休人员申请
     * @param detailId 明细id
     * @return 处理结果
     */
    @PutMapping("/pension/agree/{detailId}")
    @PermissionAnnotation(menus = {USER_PENSION})
    public CommonResult agreePension(@PathVariable Integer detailId) {
        memberService.agreePension(detailId, SURE);
        return CommonResult.success();
    }

    /**
     * 拒绝退休人员申请
     * @param detailId 明细id
     * @return 处理结果
     */
    @PutMapping("/pension/refuse/{detailId}")
    @PermissionAnnotation(menus = {USER_PENSION})
    public CommonResult refusePension(@PathVariable Integer detailId) {
        memberService.refusePension(detailId, NEGATE);
        return CommonResult.success();
    }
}
